<?php
/**
 * 项目类型管理
 * @author qianxun
 *
 */
class AdminProType extends MY_Controller{
    function AdminProType(){
        parent::MY_Controller();
        if (!$this->auth->isImport()){
            showError('您无此页面操作权限','/');
        }
    }
    /**
     * 项目类型首页
     */
    function index(){
        //面包屑
        $this->viewData['breadcrumb'][] = array('url'=>printUrl('AdminProType', 'index'),'title'=>'项目类型管理');
        $this->load->model('proTypeModel');
        $proTypeList = $this->proTypeModel->getNewList(array('proTypeId > '=>0));
        $this->viewData['proTypeList'] = $proTypeList;
        $this->load->view('AdminProType/index', $this->viewData);
    }
    /**
     * 添加或修改项目类型
     */
    function add() {
        $this->load->model('proTypeModel');
        if ($_POST){
            $proTypeId = (int)$this->input->get('proTypeId');
            $data = array(
                'proTypeName' => $this->input->post('proTypeName'),
                'statusIs' => (int)$this->input->post('statusIs'),
            );
            if ($proTypeId){
                if ($this->proTypeModel->edit(array('proTypeId'=>$proTypeId), $data)){
                    $this->proTypeModel->createCache();
                    showSuccess('修改项目类型成功');
                }else{
                    showError('修改项目类型失败');
                }
            }else{
                $data['createTime'] = time();
                if ($this->proTypeModel->add($data)){
                    $this->proTypeModel->createCache();
                    showSuccess('添加项目类型成功');
                }else{
                    showError('添加项目类型失败');
                }
            }
        }else{
            $proTypeId = (int)$this->input->get('proTypeId');
            if ($proTypeId){
                $proTypeData = $this->proTypeModel->getData(array('proTypeId'=>$proTypeId));
                $this->viewData['proTypeData'] = $proTypeData;
            }
            $this->load->view('AdminProType/add', $this->viewData);
        }
    }
}